<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
	@$connection = mysql_pconnect('localhost', 'root', '');
	if(!$connection)
	{
		echo "Không thể truy cập và cơ sở dữ liệu. Bạn vui lòng thử lại sau";
		exit;
	}
	
	function mysqlquery($string)
	{		
		$result = mysql_query($string);
		if(!$result)
			return die("query fail");
		return $result;
	}
	
	if(isset($_GET['user_id']) && isset($_COOKIE['studialusername']))
	{
	
		$user_id = $_COOKIE['user_id'];
		$user_friend = $_GET['user'];
		
		$result = mysqlquery("select * from `friends` where `user_id` = '$user_id';");
		$row_num = mysql_num_rows($result);
		if($row_num!=0)
		{
			$query = "DELETE FROM `studial`.`friends` WHERE `friends`.`user_id` = '".$user_id." and `friends`.`friend_id` = '".$user_friend."';";
			mysql_query($query);
		}
		
		$result = mysqlquery("select * from `friends` where `friend_id` = '$user_id';");
		$row_num = mysql_num_rows($result);
		if($row_num!=0)
		{
			$query = "DELETE FROM `studial`.`friends` WHERE `friends`.`friend_id` = '".$user_id." and `friends`.`user_id` = '".$user_friend."';";
			mysql_query($query);
		}
	}
?>
</body>
</html>